//
//  FunctionViewController.swift
//  SwiftTest
//
//  Created by midea on 16/3/11.
//  Copyright © 2016年 Vincent. All rights reserved.
//

import Foundation
import UIKit

private class SubPara : AnyObject {
    let content : String = "subPara is an object"
}

class FunctionViewController : BaseViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.titles = ["BaseType","Tuple","Object"]
        self.tableView?.reloadData()
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        super.tableView(tableView, didSelectRowAt: indexPath)
        
        switch indexPath.row{
        case 0:
            functionA()
            functionB("hello")
            functionC(true, int : 8)
            let int : Int32? = functionD(false, string: "world")
            print("int is " + String(describing: int))
        case 1:
            let tuple = functionE("what ")
            print("tuple is " + String(describing: tuple))
            let (subOne,_) = tuple
            print("subOne is " + String(subOne))
        case 2:
            functionName(action: "I", theMan: "Lao Huang")
            functionParaA(SubPara())
//            functionParaB([1,2,3,4])
        default:
            print("no more methods")
        }
    }
    
    fileprivate func functionA(){
        print("no para no return")
    }
    
    fileprivate func functionB(_ string : String){
        print("have para no return")
    }
    
    fileprivate func functionC(_ boolean : Bool,int : Int32) {
        print("have two paras no return")
    }
    
    fileprivate func functionD(_ boolean:Bool, string:String) -> Int32 {
        if boolean == false && string == "world" {
            return 10
        }
        return 0
    }
    
    fileprivate func functionE(_ string : String) -> (String,String) {
        let stringA = string + "hello"
        let stringB = string + "world"
        return (stringA,stringB)
    }
    
    fileprivate func functionName(action stirngA: String, theMan stringB:String) {
        print(stirngA + " bit " + stringB)
    }
    
    fileprivate func functionParaA(_ subPara:SubPara) {
        print(subPara.content)
    }
    
    fileprivate func functionParaB(_ array:AnyObject) {
        print(array)
    }

}
